import 'package:flutter/material.dart';
import 'package:device_info/device_info.dart';

class DevicePage extends StatefulWidget {
  DevicePage({Key key}) : super(key: key);

  @override
  _DevicePageState createState() => _DevicePageState();
}

class _DevicePageState extends State<DevicePage> {

  var _deviceId = '';
  var _product = '';

  @override
  void initState() {
    super.initState();
    _getDevice();
  }

  _getDevice() async{
    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
    print('设备号 ${androidInfo.androidId}');

    setState(() {
      this._deviceId = androidInfo.androidId;
      this._product = androidInfo.model;
    });

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('我的设备')
      ),
      body: Padding(
        padding: EdgeInsets.all(10),
        child: ListView(
          children: <Widget>[
            SizedBox(height: 10),
            Text('设备ID：${this._deviceId}'),
            Divider(),
            Text('设备名称：${this._product}'),
            Divider()
          ] 
        )
      )
    );
  }
}